function [] = SortBBRFile(fname)
% clear; clc; close all; fname = 'C:\Users\Mittal\Documents\Work\Code\survival-analysis\perl\NTDBNEW_Test_LD.txt';

[path name ext] = fileparts(fname);
fname_out = [path '\' name '_sorted' ext];

fp = fopen(fname,'r');
data = textscan(fp,'%s','Delimiter','\n','BufSize',2000000);
data = data{1};
fclose(fp);

y = zeros(size(data,1),1);
for i = 1:size(data,1),
    line = data{i};
    colon = find(line == ':');
    colon = colon(1);
    y(i) = str2num(line(1:colon-1));
end
y = y + 0.01*rand(length(y),1);
[y inds] = sort(y,'Descend');

data  = data(inds);
precision = 15;
for i = 1:size(data,1),
    line = data{i};
    colon = find(line == ':');
    colon = colon(1);
    data{i} = [num2str(y(i),precision) line(colon:end)];
end
if(size(unique(str2num(num2str(y,precision)))) ~= size(y,1))
    fprintf('\nError:All y are not unique, increase precision in num2str function!\n\n');
    return;
else
    fp = fopen(fname_out,'w');
    for i = 1:size(data,1),
        line = data{i};
        fprintf(fp,'%s\n',line);
    end
    fclose(fp);
end

return